import { ajax } from '../lib/ajax.js';
import { tools } from '../lib/tools.js';

let div_title = document.getElementById('div_title');
let div_source = document.getElementById('div_source');
let div_info = document.getElementById('div_info');
let title = document.querySelector('title');

// 获取url中的信息
console.log(location.href);
console.log(location.search);
console.log(location.host);
let nid = location.search.replace('?nid=', '');
console.log('nid===>', nid);

ajax.get(`/crud/news/${nid}`, {}, (data) => {
  if (!data.success) {
    alert(data.message);
    return;
  }
  let news = data.data;
  div_title.innerHTML = news.title;
  div_info.innerHTML = news.info;
  div_source.innerHTML = `  ${news.source}-${tools.formatDate(news.lastupdate)}
  `;
  title.innerHTML = news.title;
});
